<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport"
	content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta name="renderer" content="webkit">
<link rel="stylesheet" href="<%=path%>/css/pintuer.css">
<link rel="stylesheet" href="<%=path%>/css/admin.css">
<link rel="shortcut icon" href="<%=path%>/images/login.jfif">
<script src="<%=path%>/js/jquery.js"></script>
<script type="text/javascript">
	
</script>

</head>

<body>
	<div class="panel admin-panel">
		<div class="panel-head" id="add">
			<strong><span class="icon-pencil-square-o"></span>填写慢性病报销表</strong>
		</div>
		<div class="body-content">
			<form id="form-addrole" method="post" class="form-x">
			
			<div class="form-group">
					<div class="label">
						<label>姓名：</label>
					</div>
					<div class="field field-icon-right">
						<input type="text" class="input w50 input input-big" value="${member.member_name}"
							name="member_name" id="member_name_input" placeholder=""
							data-validate="required:" /> <span></span>
						<div class="tips"></div>
					</div>
				</div>
				
				<div class="form-group">
					<div class="label">
						<label>身份证号：</label>
					</div>
					<div class="field field-icon-right">
						<input type="text" class="input w50 input input-big" value="${member.people_id}"
							name="people_id" id="people_id_input" placeholder=""
							data-validate="required:" /> <span></span>
						<div class="tips"></div>
					</div>
				</div>
				
				<div class="form-group">
					<div class="label">
						<label>农合证号：</label>
					</div>
					<div class="field field-icon-right">
						<input type="text" class="input w50 input input-big" value="${member.rural_id}"
							name="rural_id" id="rural_id_input" placeholder=""
							data-validate="required:" /> <span></span>
						<div class="tips"></div>
					</div>
				</div>
				
				<div class="form-group">
					<div class="label">
						<label>报销慢性病名称：</label>
					</div>
					<div class="field field-icon-right">
						<input type="text" class="input w50 input input-big" value=""
							name="disease_name" id="disease_name_input" placeholder=""
							data-validate="required:" /> <span></span>
						<div class="tips"></div>
					</div>
				</div>
				
				<div class="form-group">
					<div class="label">
						<label>报销年度：</label>
					</div>
					<div class="field field-icon-right">
						<input type="text" class="input w50 input input-big" value=""
							name="year" id="year_input" placeholder=""
							data-validate="required:" /> <span></span>
						<div class="tips"></div>
					</div>
				</div>
				
				<div class="form-group">
					<div class="label">
						<label>家庭住址：</label>
					</div>
					<div class="field field-icon-right">
						<input type="text" class="input w50 input input-big" value="${member.family.family_adress}"
							name="family_adress" id="family_adress_input" placeholder=""
							data-validate="required:" /> <span></span>
						<div class="tips"></div>
					</div>
				</div>
				
				<div class="form-group">
					<div class="label">
						<label>费用：</label>
					</div>
					<div class="field field-icon-right">
						<input type="text" class="input w50 input input-big" value=""
							name="pay_money" id="pay_money_input" placeholder=""
							data-validate="required:" /> <span></span>
						<div class="tips"></div>
					</div>
				</div>
				
				<div class="form-group">
                <div class="label">
                    <label>付款状态：</label>
                </div>
                <div class="field">
                    <select id="status" class="input w50" name="status">
                        <option value="0">未审核</option>
                        <option value="1">待付款</option>
                        <option value="2">已付款</option>
                    </select>
                    <div class="tips"></div>
                </div>
            </div>
				
				<div class="form-group">
					<div class="label">
						<label></label>
					</div>
					<div class="field">
						<button id="add_btn" class="button bg-main icon-check-square-o"
							onclick="addReimbursement()" type="button">提交</button>
					</div>
				</div>
				
			</form>
		</div>
	</div>

</body>
<script type="text/javascript">
	//校验农合证号是否已经存在慢性病证
	$(document).ready(function() {
	   var rural_id = $("#rural_id_input").val();
		$.ajax({
			data:{rural_id:rural_id},
			type : "post",
			datatype : "json",
			url : "<%=path%>/reimbursement/certificate_check",
			async : false,
			success : function(result) {
				if(result.code==100){
				    show_validate_msg("#rural_id_input", "success", "不能查询到慢性病证，转门诊用例！");
				}else{
					show_validate_msg("#rural_id_input", "error", "✔");
				}

			}
		})
	});
	
	//校验报销的疾病是否与慢性病证上的疾病一致
	$("#disease_name_input").change(function(){
	 var disease_name = this.value;
	 var rural_id = $("#rural_id_input").val();
	   $.ajax({
	          url:"<%=path%>/reimbursement/certificate_disease_check",
	          type:"post",
	          data:{disease_name:disease_name,
	                    rural_id:rural_id},
	          success:function(result){
	          
	          	if (result.code == 100) {
					show_validate_msg("#disease_name_input", "success", "报销的慢性病与慢性病证上的不一致，转门诊用例！");
				} else {
					show_validate_msg("#disease_name_input", "error", "✔");
				}
	          }
	   })
	})
	
	function addReimbursement() {
		var member_name = $("#member_name_input").val();
		var people_id = $("#people_id_input").val();
		var rural_id = $("#rural_id_input").val();
		var disease_name = $("#disease_name_input").val();
		var year = $("#year_input").val();
		var family_adress = $("#family_adress_input").val();
		var status = $("#status").val();
		var pay_money = $("#pay_money_input").val();
		$.ajax({
			type : "post",
			url : "<%=path%>/reimbursement/reimbursement_action",
			data : {
				member_name: member_name,
				people_id: people_id,
				rural_id: rural_id,
				disease_name: disease_name,
				year:year,
				family_adress:family_adress,	
				status:status,
				pay_money:pay_money
			},
			
			success : function(result) {
			  if(result.code==100){
			     alert("报销成功！"+"\n"+"支付费用:"+JSON.stringify(result.extend.pay_money)
			     +"\n"+"本年度已报销金额:"+JSON.stringify(result.extend.aleady_money)
			     +"\n"+"本次报销金额:"+JSON.stringify(result.extend.money))
			  }else{
			  	  alert("慢性病证过期！")
			  
			  }

			}
		})
	}
	
	//校验结果提示信息
	function show_validate_msg(ele, status, msg) {
		//清除当前元素的校验状态
		$(ele).next("span").text("");
		if ("success" == status) {
			$(ele).next("span").text(msg);
		} else if ("error" == status) {
			$(ele).next("span").text(msg);
		}
	}
</script>
</html>
